package com.k12.user.service.impl;

import com.k12.user.model.entity.SysUserPost;
import com.k12.user.mapper.SysUserPostDao;
import com.k12.user.service.SysUserPostService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;
/**
 * 用户与岗位关联表(SysUserPost)表服务实现类
 *
 * @author makejava
 * @since 2025-07-28 20:53:08
 */
@Service("sysUserPostService")
public class SysUserPostServiceImpl implements SysUserPostService {
    @Resource
    private SysUserPostDao sysUserPostDao;

    /**
     * 通过ID查询单条数据
     *
     * @param userId 主键
     * @return 实例对象
     */
    @Override
    public SysUserPost queryById(Long userId) {
        return this.sysUserPostDao.queryById(userId);
    }

    /**
     * 分页查询
     *
     * @param sysUserPost 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public List<SysUserPost> queryByPage(SysUserPost sysUserPost) {
        return this.sysUserPostDao.queryAllByLimit(sysUserPost);
    }

    /**
     * 新增数据
     *
     * @param sysUserPost 实例对象
     * @return 实例对象
     */
    @Override
    public SysUserPost insert(SysUserPost sysUserPost) {
        this.sysUserPostDao.insert(sysUserPost);
        return sysUserPost;
    }

    /**
     * 修改数据
     *
     * @param sysUserPost 实例对象
     * @return 实例对象
     */
    @Override
    public SysUserPost update(SysUserPost sysUserPost) {
        this.sysUserPostDao.update(sysUserPost);
        return this.queryById(sysUserPost.getUserId());
    }

    /**
     * 通过主键删除数据
     *
     * @param userId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long userId) {
        return this.sysUserPostDao.deleteById(userId) > 0;
    }

    @Override
    public void addSysUserPost(List<SysUserPost> sysUserPost) {
        this.sysUserPostDao.insertBatch(sysUserPost);
    }

    @Override
    public List<Long> getPostIds(String tenantId, Long userId) {
        SysUserPost sysUserPost = new SysUserPost();
        sysUserPost.setTenantId(Long.valueOf(tenantId));
        sysUserPost.setUserId(userId);
        List<SysUserPost> sysUserPosts = sysUserPostDao.queryAllByLimit(sysUserPost);
        return sysUserPosts.stream().map(SysUserPost::getPostId).toList();
    }

    @Override
    public Boolean deleteUserPostByTenantId(Long userId, String tenantId) {
        return this.sysUserPostDao.deleteUserPostByTenantId(userId,tenantId);
    }

    @Override
    public int countUserPostById(Long postId, String tenantId) {
        return this.sysUserPostDao.countUserPostById(postId,tenantId);
    }

    @Override
    public int deletePostByIds(Long[] postIds, String tenantId) {
        return this.sysUserPostDao.deletePostByIds(postIds,tenantId);
    }
}
